package pjwstk.jps.result;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author s9111_s10304
 *
 */
public class BagResult implements IBagResult
{
    private Collection<ISingleResult> elements;

    /**
     * @param elements
     */
    public BagResult(Collection<ISingleResult> theElements) {
        elements = theElements;
    }

    @Override
    public Collection<ISingleResult> getElements() {
        return elements;
    }
    
    @Override
    public String toString() {
        String brString = "bag(";
        int n = 0;
        ISingleResult singleResult = null;
        for (Iterator<ISingleResult> i = elements.iterator(); i.hasNext();) {
            singleResult = (ISingleResult) i.next();
            brString += n + "=" + singleResult.toString() + ", ";
            n++;
        }
        if (4 < brString.length())
            brString = brString.substring(0, brString.length()-2); // remove last , (comma and space) added in the loop 
        brString += ")";
        return brString;
    }
}